package com.mask.roll.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mask.roll.common.code.ServiceEnums;
import com.mask.roll.common.constant.RollConstants;
import com.mask.roll.common.util.RollResponse;
import com.mask.roll.edu.entity.Course;
import com.mask.roll.edu.entity.Teacher;
import com.mask.roll.edu.service.CourseService;
import com.mask.roll.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hx
 * @since 2021/10/28 5:39 下午
 */

@RestController
@Api(tags = "前台讲师管理")
@RequestMapping("/edu/front/teacher")
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    @PostMapping("/get/page/{number}/{size}")
    @ApiOperation("分页获取讲师列表")
    public RollResponse getPage(@ApiParam("页码") @PathVariable("number") Integer number,
                                @ApiParam("页数") @PathVariable("size") Integer size){
        Page<Teacher> page = new Page<>(number, size);
        Map<String,Object> map = teacherService.getTeacherFrontList(page);

        return RollResponse.result(ServiceEnums.EDU_FRONT_TEACHER_PAGE_SUCCESS.getCode(),
                RollConstants.SUCCESS,ServiceEnums.EDU_FRONT_TEACHER_PAGE_SUCCESS.getMessage(),map);
    }

    /**
     * 获取讲师详情
     * @param teacherId
     * @return
     */
    @GetMapping("/getTeacherFrontInfo/{teacherId}")
    @ApiOperation("获取讲师详情")
    public RollResponse getTeacherFrontInfo(@PathVariable String teacherId) {
        //1 根据讲师id查询讲师基本信息
        Teacher eduTeacher = teacherService.getById(teacherId);
        //2 根据讲师id查询所讲课程
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<Course> courseList = courseService.list(wrapper);
        HashMap<String, Object> map = new HashMap<>();
        map.put("teacher",eduTeacher);
        map.put("courseList",courseList);
        return RollResponse.result(ServiceEnums.EDU_FRONT_TEACHER_DETAIL_SUCCESS.getCode(),
                RollConstants.SUCCESS,ServiceEnums.EDU_FRONT_TEACHER_DETAIL_SUCCESS.getMessage(),map);
    }


}
